﻿// Decompiled with JetBrains decompiler
// Type: NanoSockets.Address
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

using Netick;
using System;
using System.Runtime.InteropServices;
using System.Text;

#nullable disable
namespace NanoSockets;

[StructLayout(LayoutKind.Explicit, Size = 18)]
public struct Address : IEquatable<Address>, IEndPoint
{
  [FieldOffset(0)]
  public ulong address0;
  [FieldOffset(8)]
  public ulong address1;
  [FieldOffset(16 /*0x10*/)]
  public ushort port;
  [FieldOffset(16 /*0x10*/)]
  public ushort Port;

  string IEndPoint.IPAddress
  {
    get
    {
      StringBuilder ip1 = new StringBuilder();
      int ip2 = (int) UDP.GetIP(ref this, ip1, 64 /*0x40*/);
      return ip1.ToString();
    }
  }

  int IEndPoint.Port => (int) this.port;

  public bool Equals(Address other)
  {
    return (long) this.address0 == (long) other.address0 && (long) this.address1 == (long) other.address1 && (int) this.port == (int) other.port;
  }

  public override bool Equals(object obj) => obj is Address other && this.Equals(other);

  public override int GetHashCode()
  {
    return ((17 * 31 /*0x1F*/ + this.address0.GetHashCode()) * 31 /*0x1F*/ + this.address1.GetHashCode()) * 31 /*0x1F*/ + this.port.GetHashCode();
  }

  public override string ToString()
  {
    StringBuilder ip1 = new StringBuilder(64 /*0x40*/);
    int ip2 = (int) UDP.GetIP(ref this, ip1, 64 /*0x40*/);
    return $"IP:{ip1} Port:{this.port}";
  }

  public static Address CreateFromIpPort(string ip, ushort port)
  {
    Address address = new Address();
    int num = (int) UDP.SetIP(ref address, ip);
    address.port = port;
    return address;
  }
}
